from http.client import responses

from flask import Flask, request,make_response,render_template,session
app = Flask(__name__)
@app.route('/submit',methods=['POST'])
def submit():
    username = request.form.get('username')
    password = request.form.get('password')
    email = request.form.get('email')
    return f'{username},{password},{email}'

@app.route('/custom_response',methods=['POST'])
def custom_response():
    responses =  make_response("this is a custom response")
    responses.headers['X-Custom-Header'] = 'Value'
    responses.set_cookie("","")
    responses.set_data("ceshi")
    return responses


@app.route('/template/<name>',methods=['GET','POST'])
def template(name):
    return render_template('index.html', name=name)

@app.errorhandler(404)
def page_not_found(e):
    return 'Page not found', 404

@app.errorhandler(500)
def internal_server_error(e):
    return 'Internal server error', 500


# 自动生成的密钥
app.secret_key = 'your_secret_key_here'

@app.route('/set_session/<username>')
def set_session(username):
    session['username'] = username
    return f'Session set for {username}'

@app.route('/get_session')
def get_session():
    username = session.get('username')
    return f'Hello, {username}!' if username else 'No session data'

if __name__ == '__main__':
    app.run(debug=True)